﻿#light

module Dwarf_DynamicProgramming_Generator

open System
open System.IO
open System.Text
open System.ComponentModel

/// <summary>
/// The DatafileGenerator creates a randomized data file for the dynamic programming dwarf.
/// The file format is as follows:
/// 1   (int)
/// 2   (int)
/// 3   (int),(int)
///     ...
/// n   (int),(int)
/// Where line 1 has an integer with the constraint on it.  Line 2 has an integer with the number of item pairs,
/// and lines 3 through n have two integers seperated by a coma and ended by the windows newline (\n\m).
/// The weight of an item is the first element of the pair; the value is the second element of the pair.
/// </summary>

let Dwarf_DynamicProgramming_Generator (fs : FileStream, args : String[]) = 

    // subsidiary objects
    let writer = new StreamWriter(fs);
    
    //create a new random number generator
    let rand = new Random();
    
    // constants
    let average_byte_count = 8
    let count_of_digits_in_kilobyte = 1024

    //default values
    let Constraint = 500;
    let MaximumCost = 1000;
    let TotalNumberValues = 1000;
    let count_of_kilobytes = (int) args.[args.Length - 1]
    
    let TotalNumberValues = count_of_digits_in_kilobyte * count_of_kilobytes / average_byte_count;
    //write the constraint to the file
    writer.WriteLine(Constraint);

    //write the number of items to the file
    writer.WriteLine(TotalNumberValues);

    //write the random pairs to the file
    //weight, value
    for i = 0 to TotalNumberValues do
        writer.WriteLine("{0}, {1}", rand.Next(1, MaximumCost), rand.Next(1, MaximumCost));
    done

    //close the file
    writer.Close()

    true